package com.oasys.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.oasys.dao.JobMapper;
import com.oasys.dao.RoleMapper;
import com.oasys.entity.po.RolePo;
import com.oasys.entity.vo.RoleVo;
import com.oasys.service.JobService;
import com.oasys.utils.AutoGenerateIds;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Description: TODO
 * @Author: mis_wu
 * @Date: 2022/5/11
 **/
@Service
@Transactional(rollbackFor = Exception.class)
public class JobServiceImpl implements JobService {

    @Resource
    private JobMapper jobMapper;

    @Resource
    private RoleMapper roleMapper;

    /**
     * 分页查询职位
     * @param jobName 职位
     * @param page 页码
     * @param size 条数
     * @return list
     */
    @Override
    public PageInfo<RolePo> queryJobByPage(String jobName, int page, int size) {
        PageHelper.startPage(page,size);
        List<RolePo> jobList = jobMapper.queryJobByPage(jobName);
        return new PageInfo<>(jobList);
    }

    /**
     * addJOB
     * @param jobName name
     * @return
     */
    @Override
    public Boolean addJob(String jobName) {
        if (null == jobName || StringUtils.isEmpty(jobName)){
            return false;
        }
        Long roleId = AutoGenerateIds.getGenerateId();

        Integer maxRoleNo = roleMapper.getMaxRoleNo();
        return jobMapper.addJob(roleId, jobName,maxRoleNo + 1);
    }

    @Override
    public Boolean updateJob(RoleVo roleVo) {
        if (ObjectUtils.isNotEmpty(roleVo)){
            return jobMapper.updateJob(roleVo);
        }
        return false;
    }

    @Override
    public Boolean delJob(Long jobId) {
        if (null != jobId){
            return jobMapper.delJob(jobId);
        }
        return false;
    }
}
